package com.liangzhong.model.friend
{
	import com.common.stdlib.StringUtil;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.friend.vo.AddFriendVo;
	import com.liangzhong.model.friend.vo.FriendInviteVo;
	import com.liangzhong.model.friend.vo.FriendMatchResultVo;
	import com.liangzhong.model.friend.vo.FriendVo;
	
	import flash.utils.ByteArray;
	
	import lz.controls.Alert;

	/**
	 *好友模块服务器数据分析 
	 * @author lake
	 * 
	 */	
	public class FriendServerDataParse
	{
		public function FriendServerDataParse()
		{
		}
		/**
		 * 读取在线玩家数据
		 * @param data
		 */		
		public static function readOnlineList(data : ByteArray):Array
		{
			var res :Array = [];
			var strLen :int ;
			var pLen :int = data.readShort();
			var addFriendVo :AddFriendVo;
			for(var i :int = 0;i < pLen;i++)
			{
				if(data.bytesAvailable <= 0)
				{
					break;
				}
				addFriendVo = new AddFriendVo();
				addFriendVo.uid = data.readInt();
				strLen = data.readShort();
				if(strLen > 0)
				{
					addFriendVo.cname = StringUtil.readStringByByteArray(data,strLen);
				}
				strLen = data.readShort();
				if(strLen > 0)
				{
					addFriendVo.headurl = StringUtil.readStringByByteArray(data,strLen);
				}
				res.push(addFriendVo);
			}
			return res;
		}
		/**
		 *读取同意邀请要求后的数据 
		 * @param data
		 */		
		public static function readAgreeInvite(data :ByteArray):void
		{
//			var strLen :int ;
//			var friendVo :FriendVo = new FriendVo();
//			friendVo.cid 		= data.readInt();
//			friendVo.grade 		= data.readInt();
//			friendVo.score 		= data.readInt();
//			strLen 				= data.readShort();
//			friendVo.name 		= StringUtil.readStringByByteArray(data,strLen);
//			strLen 				= data.readShort();
//			friendVo.headurl2 	= StringUtil.readStringByByteArray(data,strLen);
//			AppData.getInstance().friendManager.addFriend(friendVo);
//			Alert.showErrorTip(friendVo.name +　"成为您的好友");
		}
		/**
		 *读取好友赛结果 
		 * @param data
		 * @return 
		 */		
		public static function readMatchResult(data :ByteArray):FriendMatchResultVo
		{
			var vo :FriendMatchResultVo = new FriendMatchResultVo();
			
			vo.uid 			= data.readInt();
			//vo.grade 		= data.readInt();
			//vo.score 		= data.readInt();
			//vo.platform 	= data.readByte();
			vo.rel 			= data.readByte();
			vo.match1 		= data.readByte();
			vo.match2 		= data.readByte();
			vo.match3 		= data.readByte();
			vo.match4		= data.readByte();
			vo.match5 		= data.readByte();
			
			return vo;
		}
		/**
		 *邀请好友信息 
		 * @param data
		 * @return 
		 * 
		 */		
		public static function readInviteData(data :ByteArray):FriendInviteVo
		{
			var vo :FriendInviteVo = new FriendInviteVo();
			var strLen :int ;
			vo.uid 			= data.readInt();
			strLen 			= data.readShort();
			vo.name 		= StringUtil.readStringByByteArray(data,strLen);
			strLen 			= data.readShort();
			vo.headurl 		= StringUtil.readStringByByteArray(data,strLen);
			return vo;
		}
		/**
		 *读取删除好友 
		 * @param data
		 * @return 
		 * 
		 */		
		public static function readDeleteFriend(data :ByteArray):*
		{
			var vo :Object = {};
			vo.ret = data.readInt();
			vo.uid = data.readInt();
			return vo;
		}
	}
}